package org.cst8277.ums.nas.listeners;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@Slf4j
@Data
public class DeviceListener extends AnalysisEventListener<Map<Integer, String>> {
    private List<List<String>> dataList = new ArrayList<>();

    @Override
    public void invoke(Map<Integer, String> integerStringMap, AnalysisContext analysisContext) {
        Integer rowIndex = analysisContext.readRowHolder().getRowIndex();
        System.out.println("rowIndex = " + rowIndex);
        // key为列号，value为单元格的内容
        log.info("解析到数据:{}", integerStringMap);
        // 把数据放到dataList里面，便于统一处理
        LinkedList<String> strings = new LinkedList<>();
        integerStringMap.forEach((k, v) -> {
            strings.add(v);
        });
        this.dataList.add(strings);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        log.info("数据读取完成");
    }
}
